5 HJB

5.1 Post Technology Jump

Controls:

  • \(i_k\) is a potential value for \(\frac{I_t^k}{K_t}\)

  • \(h_k\) is the distortion to capital accumulation.

State: - \(k\) is a realization of \(\log K\).

We have HJB for post technology jump as follows

In case of post damage jump, we call obtained solution as \(v \doteq \Phi^{\ell,II}\). And in case of pre damage jump, we call obtained solution as \(v \doteq\Phi^{II}\).

First order condition

Let

\[m u \doteq \delta\left(\frac{\alpha-i_k}{\exp (v)} \exp (k)\right)^{-\rho} \frac{\exp (k)}{\exp (\Phi^{m,II})}\]

Then first order condition for \(i_k\) is

\[m u=\frac{d \Phi^{\ell,II}}{dk}\left(1-\kappa i_k\right)\]

while first order condition for \(h_k\) is

\[\frac{d \Phi^{m,II}}{dk} \sigma_k=-\xi_k h_k\]

5.2 Pre technology Jump

5.2.1 Pre Technology and Post Damage Jump

Controls: - \(i_k\) is a potential value for \(\frac{I_t^k}{K_t}\) - \(i_j\) is a potential value for \(\frac{I_t^j}{K_t}\) - \(\mathcal{E}\) is a potential value for \(\mathcal{E}_t\) - \(h_k\) is the distortion to capital accumulation. - \(h_y\) is the distortion to temperature anomaly accumulation. - \(h_j\) is the distortion to R&D accumulation.

State: - \(k\) is a realization of \(\log K\). - \(y\) is a realization of \(Y\). - \(j\) is a realization of \(\log J\). - \(n\) is a realization of \(\log N\).

We attempt to solve a value function of the form

\[V^\ell(k,y,j,n) = \frac{\partial V^\ell}{\partial n} n + \Phi^\ell(k, y, j)\]

5.2.1 Pre Technology and Pre Damage Jump

Controls: - \(i_k\) is a potential value for \(\frac{I_t^k}{K_t}\) - \(i_j\) is a potential value for \(\frac{I_t^j}{K_t}\) - \(\mathcal{E}\) is a potential value for \(\mathcal{E}_t\) - \(h_k\) is the distortion to capital accumulation. - \(h_y\) is the distortion to temperature anomaly accumulation. - \(h_j\) is the distortion to R&D accumulation.

State: - \(k\) is a realization of \(\log K\). - \(y\) is a realization of \(Y\). - \(j\) is a realization of \(\log J\). - \(n\) is a realization of \(\log N\).

We attempt to solve a value function of the form

\[V(k,y,j,n) = \frac{\partial V}{\partial n} n + \Phi(k, y, j)\]
[1]:
from src.plot import plot_simulatedpath_full

plot_simulatedpath_full(graph_type="RD_Plot", graph_title = "Figure 2: R&D Investment as Percentage of GDP", yaxis_label="%", graph_range=[0,10], before15=True, abatement_cost = 0.5, rho=0.66)
[3]:
from src.plot import plot_simulatedpath_uncer_decomp

plot_simulatedpath_uncer_decomp(graph_type="RD_Plot", graph_title = "2: R&D Investment as Percentage of GDP", yaxis_label="%", graph_range=[0,10], before15=True, abatement_cost = 0.1, rho=0.66)
[1]:
from src.plot import plot_climatehist

plot_climatehist()
[2]:
from src.plot import plot_gammahist

plot_gammahist("Figure 6: Distorted climate model distribution ")

[1]:
from src.plot import plot_simulatedpath_full2

plot_simulatedpath_full2(graph_type="RD_Plot", graph_title = "Figure 2: R&D Investment as Percentage of GDP", yaxis_label="%", graph_range=[0,10], before15=True)
[2]:
from src.plot import plot_simulatedpath_uncer_decomp2

plot_simulatedpath_uncer_decomp2(graph_type="RD_Plot", graph_title = "Figure 2: R&D Investment as Percentage of GDP", yaxis_label="%", graph_range=[0,10], before15=True)
[3]:
import plotly.io as pio
import plotly.offline as pyo
import pandas as pd
import numpy as np
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import os
import sys
import pickle
sys.path.append(os.path.dirname(os.getcwd()))
pyo.init_notebook_mode()
pio.templates.default = "none"

theta_list = pd.read_csv('data/model144.csv', header=None).to_numpy()[:, 0] / 1000.
gamma_3_list = np.linspace(0, 1./3, 20)



def plot_simulatedpath_uncer_decomp(graph_type, graph_title, yaxis_label, graph_range, before15, abatement_cost, rho):

    xi_base = 100000.
    psi_0 = 0.10583
    psi_1 = 0.5
    varrho = 1120.0
    delta=0.01
    # fig = make_subplots(1, 2)
    fig = go.Figure()

    color = ["#d62728", "darkgreen", "darkorange", "navy"]

    for abatement_cost in [0.1, 0.5]:
        for rho in [0.66, 1.0, 1.5]:

            folder = "./data_simul2/2jump_step_4.00,9.00_0.0,4.0_1.0,6.0_0.0,3.0_SS_0.2,0.1,0.1_LR_0.0025_FK_phi0_{}/".format(
                abatement_cost)

            for xi_num in range(4):

                xi_list_uncertaintydecomp = 100000.0 * np.ones((5))

                if abatement_cost==0.1:

                    xi_list_uncertaintydecomp[xi_num] = 0.050

                    if xi_num==2:
                        xi_list_uncertaintydecomp[4] = 0.050
                if abatement_cost == 0.5:

                    xi_list_uncertaintydecomp[xi_num] = 0.150
                    if xi_num==2:
                        xi_list_uncertaintydecomp[4] = 0.150
                # print(xi_list_uncertaintydecomp)
                # filename = "xi_a_{}_xi_k_{}_xi_c_{}_xi_j_{}_xi_d_{}_xi_g_{}_psi_0_{}_psi_1_{}_varrho_{}_rho_{}_delta_{}_" .format(
                #     xi_base, xi_list_uncertaintydecomp[0], xi_list_uncertaintydecomp[1], xi_list_uncertaintydecomp[2], xi_list_uncertaintydecomp[3],xi_list_uncertaintydecomp[4], psi_0, psi_1, varrho, rho, delta)
                filename = "xi_a_{}_xi_k_{}_xi_c_{}_xi_j_{}_xi_d_{}_xi_g_{}_psi_0_{}_psi_1_{}_varrho_{}_rho_{}_delta_{}_" .format(
                    xi_base, xi_list_uncertaintydecomp[3], xi_list_uncertaintydecomp[0], xi_list_uncertaintydecomp[2], xi_list_uncertaintydecomp[1],xi_list_uncertaintydecomp[4], psi_0, psi_1, varrho, rho, delta)

                with open(folder + filename + "model_tech1_pre_damage_UD_simul_40direct_direct", "rb") as f:
                    model_tech1_pre_damage = pickle.load(f)
                # print(model_tech1_pre_damage.keys())
                # print(filename)
                # label = r'ξᵣ = {:.1f}'.format(xi_list_fullaversion[i])
                if xi_num == 0:
                    label = "Climate Uncertainty"
                if xi_num == 1:
                    label = "Damage Uncertainty"
                if xi_num == 2:
                    label = "Technology Uncertainty"
                if xi_num == 3:
                    label = "Producticity Uncertainty"
                # print(model_tech1_pre_damage[graph_type])
                if before15==False:
                    fig.add_trace(go.Scatter(x=model_tech1_pre_damage["years"],
                                            y=model_tech1_pre_damage[graph_type],
                                            name=label,
                                            showline=False,
                                            showlegend=False,
                                            line=dict(color=color[xi_num]),
                                            #  visible=False
                                            ))
                elif before15==True:
                    fig.add_trace(go.Scatter(x=model_tech1_pre_damage["years"][model_tech1_pre_damage["states"][:, 1]<1.5],
                                y=model_tech1_pre_damage[graph_type][model_tech1_pre_damage["states"][:, 1]<1.5],
                                name=label,
                                showline=False,
                                showlegend=False,
                                line=dict(color=color[xi_num]),

                                #  visible=False
                                ))


    for i in range(3):
        fig.data[3*2 + i]["visible"] = True
        # fig.data[3*2 + i+12]["visible"] = True

        fig.data[3*2 + i]["showlegend"] = True
        # fig.data[3*2 + 12]["showlegend"] = True

    buttons = []
    i = 0

    for abatement_cost in [0.1, 0.5]:
        for rho in [0.66, 1.0, 1.5]:

            if abatement_cost == 0.1:

                xi_list = [0.025, 0.050]
                cost_label = "Low Cost"
            if abatement_cost == 0.5:

                xi_list = [0.075, 0.150]
                cost_label = "High Cost"

            # Hide all traces
            label = cost_label+r', ρ' + '= {:.2f}'.format(rho)

            button = dict(method='update',
                          args=[
                              {
                                  'visible': [False] * (2 * 3 * 4 * 2),
                                  'showlegend': [False] * (2 * 3 * 4 * 2),
                              },
                          ],
                          label=label)
            # Enable the two traces we want to see
            # print(button['args'][0]["visible"])

            button['args'][0]["visible"][4*i + 0] = True
            button['args'][0]["visible"][4*i + 1] = True
            button['args'][0]["visible"][4*i + 2] = True
            button['args'][0]["visible"][4*i + 3] = True

            button['args'][0]["showlegend"][4*i + 0] = True
            button['args'][0]["showlegend"][4*i + 1] = True
            button['args'][0]["showlegend"][4*i + 2] = True
            button['args'][0]["showlegend"][4*i + 3] = True

            i = i+1
            # Add step to step list
            buttons.append(button)

    fig.update_layout(
        updatemenus=[
            dict(
                type="buttons",
                buttons=buttons,
                # direction="right",
                active=2,
                x=1.3,
                y=0.7,
                # xanchor="left",
                # yanchor="top",
                pad={"r": 10,
                     "t": 10, "b": 10},
                showactive=True
            )
        ])


    fig.update_xaxes(showgrid=False, showline=True,
                     title="Years", range=[0, 40])
    fig.update_yaxes(showgrid=False,
                     showline=True,
                     range=graph_range,
                     title_text= yaxis_label,
                     tickformat=".2f")
    # fig.update_yaxes(showgrid=False, showline=True,
    #                  range=[1., 2.1], col=2, row=1)
    # fig.update_yaxes(tickvals=[1, 1.2, 1.4, 1.5, 1.6, 1.8, 2.0],
    #                  tickformat=".1f",
    #                  col=2,
    #                  row=1)
    # fig.update_layout(height=400, width=1280)
    fig.update_layout(
        title=graph_title,
        barmode="overlay",
        plot_bgcolor="white",
        width=800,
        height=600,
        margin=dict(l=50, r=0))

    return fig
[2]:
# from src.plot import plot_simulatedpath_uncer_decomp2

plot_simulatedpath_uncer_decomp2(graph_type="RD_Plot", graph_title = "Figure 11: R&D Investment as Percentage of GDP", yaxis_label="%", graph_range=[0,10], before15=True)
[ ]: